package service;

import domain.Category;
import domain.Item;
import domain.Product;
import persistence.CartgoryDao;
import persistence.ItemDao;
import persistence.ProductDao;
import persistence.impl.CategoryDAOImpl;
import persistence.impl.ItemDAOImpl;
import persistence.impl.ProductDAOImpl;

import java.util.List;

public class CatelogService {
    private CartgoryDao cartgoryDao;
    private ProductDao productDao;
    private ItemDao itemDao;

    public CatelogService(){
        this.cartgoryDao=new CategoryDAOImpl();
        this.productDao=new ProductDAOImpl();
        this.itemDao=new ItemDAOImpl();
    }

    public List<Category> getCategoryList() {
        return this.cartgoryDao.getCategoryList();
    }

    public Category getCategory(String categoryId) {
        return this.cartgoryDao.getCategory(categoryId);
    }

    public Product getProduct(String productId) {
        return this.productDao.getProduct(productId);
    }

    public List<Product> getProductListByCategory(String categoryId) {
        return this.productDao.getProductListByCategory(categoryId);
    }

    public List<Product> searchProductList(String keyword) {
        return this.productDao.searchProductList("%" + keyword.toLowerCase() + "%");
    }

    public List<Item> getItemListByProduct(String productId) {
        return this.itemDao.getItemListByProduct(productId);
    }

    public Item getItem(String itemId) {
        return this.itemDao.getItem(itemId);
    }

    public boolean isItemInStock(String itemId) {
        return this.itemDao.getInventoryQuantity(itemId) > 0;
    }
}
